Skip to contentSkip to conversation

New patch OpenSC support for OpenVPN 2.0.2

Openvpn-devel C. Ruiz, Ivan 2 participants 2 messages Sep 8, 2005 – Sep 9, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw
Quoted 19 lines

Hi there,

I took Fritz Elfert's patch that enables the use of openvpn and opensc smartcards and modified it a little bit:
- Original post of Fritz: http://openvpn.net/archive/openvpn-devel/2005-02/msg00000.html
- Take out all the code for PIN dialog window under MSWindows and X-Xindows from the original patch.
- Keeped the --opensc-cert option to specify the certificate ID to use among those stored in the smartcard.
- Added an option --opensc-authfile to specify a file to read the smartcard PIN from it or "stdin" to let the user input it from the console.
- Added an option --opensc-pin to specify the PIN via command-line or configuration file.
- --opensc_authfile and opensc_pin are mutually exclusive
- If only --opensc-cert is given (no PIN options) it wil ask for a PIN from the console.

It's tested under Linux Debian with OpenSC and etoken from alladin. But it should work under Windows as well. I haven't tested as I don't run a development environment in Windows.

Can this be merged in the next version? I've been reading the posts proposing to implement this other ways, but consider that this code already works. I would include it know and then implement a better aproach to support smartcards in case it's needed, something that I'm not yet convinced of.

Attached is the diff file for 2.0.2 version of OpenVPN.

Quoted 1 line

<<openvpn-support-opensc.diff>>

Quoted 11 lines

Iván Casado Ruiz
SADIEL, S.A.
C/ Isaac Newton s/n, Isla de la Cartuja 41092 SEVILLA Tel. 95 5043600 Av. Alberto Alcocer, 46-B 28016 MADRID Tel. 91 4583492
Av. Constitución, 4 06800 MERIDA Tel. 92 4373620
C/ Ronda Sant Pere, 17 08010 BARCELONA Tel. 93 3425759
http://www.sadiel.es

config.h.in +6 -0
diff -urN openvpn-2.0.2/config.h.in openvpn-2.0.2parcheado/config.h.in
@@ -87,6 +87,9 @@
 /* Define to 1 if you have the `ENGINE_cleanup' function. */
 #undef HAVE_ENGINE_CLEANUP
 
+/* Define to 1 if you have the `ENGINE_get_default_RSA' function. */
+#undef HAVE_ENGINE_GET_DEFAULT_RSA
+
 /* Define to 1 if you have the `ENGINE_load_builtin_engines' function. */
 #undef HAVE_ENGINE_LOAD_BUILTIN_ENGINES
 
@@ -454,6 +457,9 @@
 /* Use LZO compression library */
 #undef USE_LZO
 
+/* Use OpenSC library */
+#undef USE_OPENSC
+
 /* Use pthread-based multithreading */
 #undef USE_PTHREAD
 
configure.ac +41 -0

59 lines not on this page · raw message

Makefile.am +1 -0
diff -urN openvpn-2.0.2/Makefile.am openvpn-2.0.2parcheado/Makefile.am
@@ -65,6 +65,7 @@
 	multi.c multi.h \
         ntlm.c ntlm.h \
 	occ.c occ.h occ-inline.h \
+	opensc.c opensc.h \
 	openvpn.c openvpn.h \
 	openvpn-plugin.h \
 	options.c options.h \
opensc.c +557 -0

557 lines not on this page · raw message

opensc.h +7 -0
diff -urN openvpn-2.0.2/opensc.h openvpn-2.0.2parcheado/opensc.h
@@ -0,0 +1,7 @@
+/*	opensc.h   */
+#ifndef _OPENSC_H_
+#define _OPENSC_H_
+#ifdef USE_OPENSC
+int SSL_CTX_use_OpenSC(SSL_CTX *ssl_ctx, const char *cert_prop, const char *pin_file, const char *pin);
+#endif
+#endif

Los ficheros binarios openvpn-2.0.2/openvpn y openvpn-2.0.2parcheado/openvpn son distintos

openvpn.spec +12 -1
diff -urN openvpn-2.0.2/openvpn.spec openvpn-2.0.2parcheado/openvpn.spec
@@ -7,6 +7,9 @@
 #
 # Disable PAM plugin
 #   rpmbuild -tb [openvpn.x.tar.gz] --define 'without_pam 1'
+# Disable OpenSC support
+#   rpmbuild -tb [openvpn.x.tar.gz] --define 'without_opensc 1'
+#
 #
 # Allow passwords to be read from files
 #   rpmbuild -tb [openvpn.x.tar.gz] --define 'with_password_save 1'
@@ -36,6 +39,9 @@
 BuildRequires: openssl-devel >= 0.9.6
 Requires:      openssl       >= 0.9.6
 
+%{!?without_opensc:BuildRequires: opensc-devel >= 0.9.1}
+%{!?without_opensc:Requires:      opensc       >= 0.9.1}
+
 %if "%{_vendor}" == "Mandrakesoft"
 %{!?without_lzo:BuildRequires: liblzo1-devel >= 1.07}
 %{!?without_lzo:Requires:      liblzo1       >= 1.07}
@@ -96,7 +102,12 @@
 %setup -q
 
 %build
-%configure --disable-dependency-tracking %{?with_password_save:--enable-password-save} %{?without_lzo:--disable-lzo} %{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
+%configure --disable-dependency-tracking \
+    %{?with_password_save:--enable-password-save} \
+    %{?without_lzo:--disable-lzo} \
+    %{?without_opensc:--disable-opensc} \
+    %{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
+
 %__make
 %__strip %{name}
 
openvpn.spec.in +12 -1
diff -urN openvpn-2.0.2/openvpn.spec.in openvpn-2.0.2parcheado/openvpn.spec.in
@@ -7,6 +7,9 @@
 #
 # Disable PAM plugin
 #   rpmbuild -tb [openvpn.x.tar.gz] --define 'without_pam 1'
+# Disable OpenSC support
+#   rpmbuild -tb [openvpn.x.tar.gz] --define 'without_opensc 1'
+#
 #
 # Allow passwords to be read from files
 #   rpmbuild -tb [openvpn.x.tar.gz] --define 'with_password_save 1'
@@ -36,6 +39,9 @@
 BuildRequires: openssl-devel >= 0.9.6
 Requires:      openssl       >= 0.9.6
 
+%{!?without_opensc:BuildRequires: opensc-devel >= 0.9.1}
+%{!?without_opensc:Requires:      opensc       >= 0.9.1}
+
 %if "%{_vendor}" == "Mandrakesoft"
 %{!?without_lzo:BuildRequires: liblzo1-devel >= 1.07}
 %{!?without_lzo:Requires:      liblzo1       >= 1.07}
@@ -96,7 +102,12 @@
 %setup -q
 
 %build
-%configure --disable-dependency-tracking %{?with_password_save:--enable-password-save} %{?without_lzo:--disable-lzo} %{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
+%configure --disable-dependency-tracking \
+    %{?with_password_save:--enable-password-save} \
+    %{?without_lzo:--disable-lzo} \
+    %{?without_opensc:--disable-opensc} \
+    %{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
+
 %__make
 %__strip %{name}
 
options.c +53 -0

83 lines not on this page · raw message

options.h +5 -0
diff -urN openvpn-2.0.2/options.h openvpn-2.0.2parcheado/options.h
@@ -369,6 +369,11 @@
 #ifdef WIN32
   const char *cryptoapi_cert;
 #endif
+#ifdef USE_OPENSC
+  const char *opensc_cert;
+  const char *opensc_pin;
+  const char *opensc_authfile;
+#endif
 
   /* data channel key exchange method */
   int key_method;
ssl.c +15 -0
diff -urN openvpn-2.0.2/ssl.c openvpn-2.0.2parcheado/ssl.c
@@ -53,6 +53,10 @@
 #include "status.h"
 #include "gremlin.h"
 
+#ifdef USE_OPENSC
+#include "opensc.h"
+#endif
+
 #ifdef WIN32
 #include "cryptoapi.h"
 #endif
@@ -847,6 +851,17 @@
     {
       /* Use seperate PEM files for key, cert and CA certs */
 
+#ifdef USE_OPENSC
+      if (options->opensc_cert)
+	{
+	  /* Load Certificate and Private Key */
+	  if (!SSL_CTX_use_OpenSC(ctx, options->opensc_cert, options->opensc_authfile, options->opensc_pin))
+	    msg (M_SSLERR, "Cannot load certificate \"%s\" from OpenSC Framework",
+		 options->opensc_cert);
+	}
+      else
+#endif
+
 #ifdef WIN32
       if (options->cryptoapi_cert)
 	{
#1 lore raw
Quoted 6 lines · Ivan

Hi there,

I took Fritz Elfert's patch that enables the use of openvpn and opensc smartcards and modified it a little bit:

Can this be merged in the next version? I've been reading the posts proposing to implement this other ways, but consider that this code already works. I would include it know and then implement a better aproach to support smartcards in case it's needed, something that I'm not yet convinced of.

Hello!
Good job!

But opensc is not a standard/popular interface for smartcards... PKCS#11 is much more common interface, even opensc supply PKCS#11 interface.

May I take this patch and try to convert it to PKCS#11?
The problem is that I don't know openssl very well... But I think that this patch will help a lot.

I think that merging PKCS#11 code will be much better than merging opensc code, since it will allow more smartcard types to be used.

Best Regards,
Alon Bar-Lev.